package com.song.demo.webmvc.practice.controller;

import com.song.demo.webmvc.annotation.GPAutowired;
import com.song.demo.webmvc.annotation.GPController;
import com.song.demo.webmvc.annotation.GPRequestMapping;
import com.song.demo.webmvc.annotation.GPRequestParam;
import com.song.demo.webmvc.practice.service.IQueryService;
import com.song.demo.webmvc.servlet.GPModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

@GPController
@GPRequestMapping("/demo")
public class QueryController {

    @GPAutowired("queryServiceImpl")
    private IQueryService queryService;

    @GPRequestMapping("/query")
    public GPModelAndView query(HttpServletRequest request, HttpServletResponse response, @GPRequestParam("name") String name){
        String result = queryService.query(name);
        GPModelAndView gpModelAndView = new GPModelAndView("first.html");
        HashMap<String, Object> model = new HashMap<>();
        model.put("name",result);
        gpModelAndView.setModel(model);

        return gpModelAndView;

    }
}
